package gui;

import java.awt.Graphics2D;
import java.awt.Point;

public class TowerSelectionButtonGroup extends MenuItem {

	TowerButton[][] buttons;

	public TowerSelectionButtonGroup(int[][] codes, int xpos, int ypos) {
		super(xpos, ypos);
		buttons = new TowerButton[codes.length][codes[0].length];

		for (int cont = 0; cont < codes.length; cont++) {
			for (int cont2 = 0; cont2 < codes[cont].length; cont2++) {
				buttons[cont][cont2] = new TowerButton(codes[cont][cont2]);
				buttons[cont][cont2].setPosition(cont * buttons[cont][cont2].getWidth(), cont2 * buttons[cont][cont2].getHeight());
			}
		}
	}

	@Override
	public void generateImage() {
		// TODO Auto-generated method stub

	}

	@Override
	public void renderComponent(Graphics2D g2d) {
		super.renderComponent(g2d);
		
		for (int cont = 0; cont < buttons.length; cont++) {
			for (int cont2 = 0; cont2 < buttons[cont].length; cont2++) {
				buttons[cont][cont2].render(g2d);
			}
		}
		
	}

	/* (non-Javadoc)
	 * @see gui.MenuItem#updateMouse(java.awt.Point)
	 */
	@Override
	public void updateMouse(Point p) {
		// TODO Auto-generated method stub
		for (int cont = 0; cont < buttons.length; cont++) {
			for (int cont2 = 0; cont2 < buttons[cont].length; cont2++) {
				buttons[cont][cont2].updateMouse(p);
				if(buttons[cont][cont2].isSelected()){
					try{
						buttons[cont-1][cont2].setAlpha(buttons[cont-1][cont2].getAlpha() + 0.4f);
						buttons[cont+1][cont2].setAlpha(buttons[cont+1][cont2].getAlpha() + 0.4f);
						buttons[cont][cont2+1].setAlpha(buttons[cont][cont2+1].getAlpha() + 0.4f);
						buttons[cont][cont2-1].setAlpha(buttons[cont][cont2-1].getAlpha() + 0.4f);
					}catch(Exception e){
						
					}
				}
			}
		}
	}
	
	

}
